﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>判断文本中回车的数量</title>
    <script type="text/javascript" language="JavaScript">
        function getCount(){
            let count = document.all('TextArea1').innerHTML.split('\n').length -1;  // 获取回车的个数
            alert("总共有" + count + "个回车");
        }
        
    </script>
</head>
<body>

    <textarea id="TextArea1" cols="30" rows="8"></textarea>
    <input id="Button1" type="button"  value="获取" onclick="getCount()" />

</body>
</html>